package com.example.viewactivity;

//import com.example.database.R;

import com.example.logic.CityManage;
import com.example.viewactivity.*;
import com.example.weather.*;

import android.app.Activity;
import android.content.Intent;
import android.database.DataSetObserver;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.Adapter;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.TextView;

public class City_add  extends Activity{
	private AutoCompleteTextView autotext;
	private TextView textview1;
	private CityManage cityMange;
	private ArrayAdapter<String> arrayAdapter;
	private AutoCompleteTextView comTextView;
	    @Override
	    protected void onCreate(Bundle savedInstanceState) {
	        super.onCreate(savedInstanceState);
	        setContentView(R.layout.city_add);
	        cityMange = new CityManage(City_add.this);
	        autotext =(AutoCompleteTextView) findViewById(R.id.autotext);
	        autotext.addTextChangedListener(new TextWatcher() {
				
				@Override
				public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
					// TODO Auto-generated method stub
					String cityName = autotext.getText().toString();
				    String [] citys= cityMange.searchItem(cityName);
			        arrayAdapter = new ArrayAdapter<String>(City_add.this, android.R.layout.simple_list_item_1,citys);
			        autotext.setAdapter(arrayAdapter);
			        autotext.setOnItemClickListener(new AdapterView.OnItemClickListener() {
			        
						@Override
						public void onItemClick(AdapterView<?> parent, View view,int position, long id) {
							// TODO Auto-generated method stub
							CustomToast.showToast(City_add.this,  "item onclick " + parent.getItemAtPosition(position), 1000);
							Intent i = new Intent(City_add.this,City_view.class);
							startActivity(i);
						}
					});
					
				}
				
				@Override
				public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
						int arg3) {
					// TODO Auto-generated method stub
					
				}
				
				@Override
				public void afterTextChanged(Editable arg0) {
					// TODO Auto-generated method stub
					
				}
			});
	    
	        textview1 = (TextView)findViewById(R.id.text_cancel);
	        textview1.setOnClickListener(new OnClickListener() {
				
				@Override
				public void onClick(View arg0) {
					// TODO Auto-generated method stub
					Intent i = new Intent(City_add.this,City_view.class);
					startActivity(i);
				}
			});
	        
	       /* comTextView = (AutoCompleteTextView)findViewById(R.id.autotext);
	        comTextView.setOnKeyListener(new OnClickListener(){
	        	if(keyCode==KeyEvent.KEYCODE_ENTER){
	        	InputMethodManagerimm=(InputMethodManager)v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
	        	if(imm.isActive()){
	        	imm.hideSoftInputFromWindow(v.getApplicationWindowToken(),0);
	        	}
	        	}
	        	});*/
	        
	    }
}


